package com.treasure.mall.biz.service.core.order.impl;

import com.treasure.mall.biz.entity.order.SubOrderLogPO;
import com.treasure.mall.biz.repository.order.SubOrderLogRepository;
import com.treasure.mall.biz.service.core.order.SubOrderLogService;
import com.treasure.mall.zbq.common.ienum.order.OrderEnums;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author allan
 * @version 1.0.0
 * @date 2020/6/11
 */
@Service
public class SubOrderLogServiceImpl implements SubOrderLogService {
    @Autowired
    private SubOrderLogRepository logRepository;
    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;

    @Override
    public void log(String subOrderId, OrderEnums.Operation operation, Long operatorId, String operatorName) {
        taskExecutor.execute(() -> {
            //订单日志
            SubOrderLogPO logPO = new SubOrderLogPO();
            logPO.setSubOrderId(subOrderId);
            logPO.setOperation(operation);
            logPO.setOperatorId(operatorId);
            logPO.setOperatorName(operatorName);

            logRepository.save(logPO);
        });
    }

    @Override
    public List<SubOrderLogPO> findByOrderId(String subOrderId) {
        return logRepository.findBySubOrderId(subOrderId);
    }
}
